import http from '@/http';
import type { User, UserQuery, UserForm, PageResult } from './UserModel';

// 获取用户列表（分页）
export const getUserList = (params: UserQuery) => {
  return http.post<PageResult<User>>('/api/user/list', params);
};

// 添加用户
export const addUser = (data: UserForm) => {
  return http.post<boolean>('/api/user/add', data);
};

// 更新用户
export const updateUser = (data: UserForm) => {
  return http.put<boolean>('/api/user/update', data);
};

// 删除用户（逻辑删除）
export const deleteUser = (id: number) => {
  return http.delete<boolean>(`/api/user/delete/${id}`);
};

// 批量删除用户（逻辑删除）
export const deleteUsers = (ids: number[]) => {
  return http.delete<boolean>('/api/user/delete/batch', { data: ids });
};

// 获取用户详情
export const getUserDetail = (id: number) => {
  return http.get<User>(`/api/user/detail/${id}`);
};

// 重置用户密码
export const resetUserPassword = (id: number, newPassword: string) => {
  return http.put<boolean>(`/api/user/reset-password/${id}`, { password: newPassword });
};

// 修改用户状态
export const updateUserStatus = (id: number, deleted: number) => {
  return http.put<boolean>(`/api/user/status/${id}`, { deleted });
};

